package com.wisdom.benefit.jufa.widget;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.util.AttributeSet;

import androidx.appcompat.widget.AppCompatRadioButton;

/**
 * 图标右上角支持加点
 * Created by zhoudawei on 2017/4/10.
 */

public class PointRadioButton extends AppCompatRadioButton {

    private Paint mPaint;
    private boolean mShowPoint;

    public PointRadioButton(Context context) {
        this(context, null);
    }

    public PointRadioButton(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public PointRadioButton(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    }

    public void showPoint(int pointColor, int width) {
        mShowPoint = true;
        mPaint.setColor(pointColor);
        mPaint.setStrokeWidth(width);
        mPaint.setStrokeCap(Paint.Cap.ROUND);
        postInvalidate();
    }

    public void hidePoint() {
        mShowPoint = false;
        postInvalidate();
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        if (getCompoundDrawables()[1] != null && mShowPoint) {
            canvas.drawPoint(getWidth() / 2f + getCompoundDrawables()[1].getIntrinsicWidth() / 2f + mPaint.getStrokeWidth() / 2,
                    mPaint.getStrokeWidth() / 2, mPaint);
        }
    }
}
